#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 5050, M = 2e5 + 10, INF = 0x3f3f3f3f;
int n, m;
int fa[N];
struct node
{
    int x;
    int y;
    int z;
}a[M];
bool cmp(node& s1, node& s2)
{
    return s1.z < s2.z;
}
int find(int s)
{
    return s == fa[s] ? fa[s] : fa[s] = find(fa[s]);
}
int kk()
{
    sort(a + 1, a + 1 + m, cmp);
    int cnt = 0;
    int ret = 0;
    for (int i = 1; i <= m; i++)
    {
        int x = a[i].x;
        int y = a[i].y;
        int fx = find(x);
        int fy = find(y);
        if (fx != fy)
        {
            cnt++;
            ret += a[i].z;
            fa[fx] = fy;
        }
    }
    return cnt == n - 1 ? ret : INF;
}
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= m; i++)
    {
        cin >> a[i].x >> a[i].y >> a[i].z;
    }
    for (int i = 1; i <= n; i++)
    {
        fa[i] = i;
    }
    int ret = kk();
    if (ret == INF)
    {
        cout << "orz";
    }
    else
    {
        cout << ret;
    }
    return 0;
}